import numpy as np
print('defining the problem geometry')
import environment_pool as env
thin_wires = env.thin_wires_pool
bricks  = env.bricks_pool
spheres = env.spheres_pool
brian = env.brian_pool
mapC2M = env.mapC2M_pool

def age_gender(age,female):
    from scipy.io import loadmat
    if (0<=age.find('22-25')) and female == 1:
        return loadmat('brian_female_22_25.mat') # 加载女性22-25岁数据
    elif (0<=age.find('22-25')) and female == 0:
        return loadmat('brian_male_22_25.mat')   # 加载男性22-25岁数据（示例）
    elif (0<=age.find('26-30')) and female == 1:
        return loadmat('brian_female_26_30.mat')
    elif (0<=age.find('26-30')) and female == 0:
        return loadmat('brian_male_26_30.mat')
    elif (0<=age.find('31-35')) and female == 1:
        return loadmat('brian_female_26_30.mat')
    elif (0<=age.find('31-35')) and female == 0:
        return loadmat('brian_male_31_35.mat')
    else:
        print('未找到匹配的数据文件！请检查年龄或性别输入。')
        exit(-1)
## 选择人脑类型

age = env.brian_pool["age"]
female = env.brian_pool["female"]
brian_data = age_gender(age,female)
#from scipy.io import loadmat
#brian_data = loadmat('brian_female_22_25_coarse.mat')

brian["n3density"]           = brian_data["n2density"]
brian["n3tissueMatrix_deps"] = brian_data["n2tissueMatrix_deps"] 
brian["n3tissueMatrix_eps"]  = brian_data["n2tissueMatrix_eps"]  
brian["n3tissueMatrix_sigma"]= brian_data["n2tissueMatrix_sigma"]
brian["n3tissueMatrix_tau_k"]= brian_data["n2tissueMatrix_tau_k"]
if(env.mesh_type_pool>0):
    from define_problem_space_parameters import icoat_pool
    from define_problem_space_parameters import material_types
    icoat = icoat_pool
    n3tissueMatrix_eps = np.zeros(icoat.shape)
    n3tissueMatrix_sigma = np.zeros(icoat.shape)
    n3tissueMatrix_deps = np.zeros(icoat.shape)
    n3tissueMatrix_tau_k = np.zeros(icoat.shape)
    n3density = np.zeros(icoat.shape)
    x_size, y_size, z_size = icoat.shape
    icoat_mat = np.zeros((x_size, y_size, z_size))
    for ii in np.arange(x_size):
        for jj in np.arange(y_size):
            for kk in np.arange(z_size):
                icoat0 = icoat[ii,jj,kk]
                ind_mat = mapC2M[icoat0]
                icoat_mat[ii,jj,kk] = ind_mat
                n3tissueMatrix_eps[ii,jj,kk]= material_types[ind_mat]["eps_r"] 
                n3tissueMatrix_sigma[ii,jj,kk]= material_types[ind_mat]["sigma_e"] 
                n3tissueMatrix_deps[ii,jj,kk]= material_types[ind_mat]["deps"] 
                n3tissueMatrix_tau_k[ii,jj,kk]= material_types[ind_mat]["tau_k"] 
                n3density[ii,jj,kk]= material_types[ind_mat]["density"] 
